#include <tools.h>
#include <standard/system.h>
#include <standard/resourcemanager.h>
#include "terraintexturelist.h"
#include "global.h"

CTerrainTextureList::CTerrainTextureList(){

}
CTerrainTextureList::~CTerrainTextureList(){
    RESOURCE_REMOVEGROUP( 11 );
}
void CTerrainTextureList::Init( const char* strResourceSpace ){
    m_strResourceSpace = strResourceSpace;
}
CTexture* CTerrainTextureList::GetTextureFile( const char* strFileName ){
    CTexture* _pResult = NULL;
    uint32 _nHashCode = HashString( strFileName );
    map<uint32, CTexture*>::iterator it = m_vTextureList.find( _nHashCode );
    if( it == m_vTextureList.end() ){
        char _strText[256];
        _pResult = RESOURCE_GETTEXTURE( Format( _strText, 256, "%s/gamespace/%s/terrainart/%s", g_strResourceWorkPath, m_strResourceSpace, strFileName ), 11 );
        m_vTextureList.insert( _nHashCode, _pResult );
        m_vTextureNameList.insert( _pResult, string32( strFileName ) );
    }else{
        _pResult = it.second();
    }
    return _pResult;
}
const char* CTerrainTextureList::GetTextureName( CTexture* pTexture ){
    map<CTexture*, string32 >::iterator it = m_vTextureNameList.find( pTexture );
    if( it == m_vTextureNameList.end() ){
        return NULL;
    }
    return it.second().c_str();
}